﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace ControleFinanceiro
{
    public partial class wfDinamico : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            carregadados();
        }

        private void carregadados()
        {
            try
            {
                using (SqlConnection conexao = new SqlConnection())
                {
                    conexao.ConnectionString = Properties.Settings.Default.conecte;
                    conexao.Open();
                    SqlCommand buscar = new SqlCommand();
                    buscar.CommandText = "SELECT * FROM tbFuncionario";
                    buscar.CommandType = System.Data.CommandType.Text;
                    buscar.Connection = conexao;
                    SqlDataReader DR;
                    DR = buscar.ExecuteReader();
                    Literal lista = new Literal();
                    int contador = 0;
                    lista.Text += ("<div id='tabela'>");
                    lista.Text += ("<table id='tbfuncionarios'>");
                    lista.Text += (" <tr class='titulo'>");
                    lista.Text += ("<td>SELECIONAR</td>");
                    lista.Text += ("<td>CÓDIGO</td>");
                    lista.Text += ("<td>NOME</td>");
                    lista.Text += ("<td>CARGO</td>");
                    lista.Text += ("<td>DEPARTAMENTO</td>");
                    lista.Text += ("<td>SALÁRIO</td>");
                    lista.Text += ("</tr>");
                    while (DR.Read())
                    {
                        contador += 1;
                        lista.Text += ("<tr class='linha'>");
                        lista.Text += (String.Format("<td style='text-align:center'><input id='Button{0}' type='button' value='Selecionar'/></td>", contador));
                        lista.Text += (String.Format("<td style='text-align:center'>{0}</td>", DR.GetInt32(0)));
                        lista.Text += (String.Format("<td>{0}</td>", DR.GetString(1)));
                        lista.Text += (String.Format("<td>{0}</td>", DR.GetString(2)));
                        lista.Text += (String.Format("<td>{0}</td>", DR.GetString(3)));
                        lista.Text += (String.Format("<td style='text-align:center'>{0:C2}</td>", DR.GetDecimal(4)));
                        lista.Text += ("</tr>");
                    }

                    lista.Text += ("</table>");
                    lista.Text += ("</div>");
                    phRecebehtml.Controls.Add(lista);
                    conexao.Close();
                }

            }
            catch (Exception error)
            {
                Response.Write("Error: " + error.Message);

            }


        }





    }
}